/**
 * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com)
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.zhou.base.resilience4j.test.handler;

import cn.afterturn.easypoi.excel.entity.result.ExcelVerifyHandlerResult;
import cn.afterturn.easypoi.handler.inter.IExcelVerifyHandler;
import com.google.common.collect.Sets;
import com.zhou.base.resilience4j.test.model.ao.ImportStudentAo;
import org.apache.commons.lang3.StringUtils;

import java.util.Set;


public class ExcelVerifyStudentHandlerImpl implements IExcelVerifyHandler<ImportStudentAo> {

    //校验文件中是否有重复数据
    private Set<String> idCards = Sets.newHashSet();

    private int i = 1;

    @Override
    public ExcelVerifyHandlerResult verifyHandler(ImportStudentAo obj) {
        StringBuilder builder = new StringBuilder();
        obj.setId(++i);
        if (StringUtils.isNotEmpty(obj.getIdCard()) && !idCards.add(obj.getIdCard())) {
            builder.append("文件中身份证号重复");
            return new ExcelVerifyHandlerResult(false, builder.toString());
        }

        return new ExcelVerifyHandlerResult(true);
    }

}
